<?php

namespace App\Admin\Controllers\Audit;

use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Row;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Column;

use App\Http\Controllers\Controller;


class SchoolController extends Controller
{
    use HasResourceActions;
    protected $header = '学校审核';

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header($this->header);
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header($this->header)
            ->description('Detail')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header($this->header);
            $content->description('description');
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(User::class, function (Grid $grid) {


            //去除创建按钮
            $grid->disableCreateButton();

            //搜索栏
            $grid->filter(function (Grid\Filter $filter) {
                $filter->disableIdFilter();
            });

            //操作栏
            $grid->actions(function (Grid\Displayers\Actions $actions){
                $actions->disableDelete();
            });

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(User::class, function (Form $form) {

            $form->display('id', '用户id');
            $form->display('telephone', '手机号');
            $form->select('customer_status', '客户状态')
                ->options(User::$customer_status_map);
            $form->select('importance', '重要程度')
                ->options(User::$importance_map);
            $form->textarea('note','跟进记录');


            $form->disableViewCheck();
            $form->disableEditingCheck();

        });
    }

    public function detail($id)
    {
        $show = new Show(User::findOrFail($id));

        $show->telephone('手机号');
        $show->username('用户名');
        $show->customer_status('客户状态');
        $show->importance('重要程度');
        $show->note('跟进记录');

        return $show;
    }




}
